package com.spring.demo.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class AppProperties {

	private static final Properties PROP = new Properties();

	static {
		InputStream is = AppProperties.class
				.getResourceAsStream("/app.properties");
		try {
			PROP.load(is);
			is.close();
		} catch (IOException e) {
			throw new RuntimeException("app.properties file not found!");
		}
	}

	public static String get(String key) {
		return PROP.getProperty(key);
	}

	/**
	 * 获取oxm文件保存目录
	 * 
	 * @return
	 */
	public static File getOxmPathDir() {
		File oxmPathDir = new File(AppProperties.get(OXM_PATH_DIR_KEY));
		if (!oxmPathDir.exists()) {
			oxmPathDir.mkdirs();
		}
		if (!oxmPathDir.isDirectory()) {
			throw new RuntimeException("oxm path dir is a path!");
		}

		return oxmPathDir;
	}

	/**
	 * oxm文件保存目录
	 */
	public static final String OXM_PATH_DIR_KEY = "oxmPathDir";
}
